#include <windows.h>
#include "Display_LX.h"
#include "regmgr.h"


TCHAR *LXResolutions[116] = {
	TEXT("640 480 60"),
	TEXT("640 480 75"),
	TEXT("640 480 85"),
	TEXT("640 480 90"),
	TEXT("640 480 100"),
	TEXT("800 600 60"),
	TEXT("800 600 75"),
	TEXT("800 600 85"),
	TEXT("800 600 90"),
	TEXT("800 600 100"),
	TEXT("1024 768 60"),
	TEXT("1024 768 75"),
	TEXT("1024 768 85"),
	TEXT("1024 768 90"),
	TEXT("1024 768 100"),
	TEXT("1152 864 60"),
	TEXT("1152 864 75"),
	TEXT("1152 864 85"),
	TEXT("1152 864 90"),
	TEXT("1152 864 100"),
	TEXT("1280 1024 60"),
	TEXT("1280 1024 75"),
	TEXT("1280 1024 85"),
	TEXT("1280 1024 90"),
	TEXT("1280 1024 100"),
	TEXT("1600 1200 60"),
	TEXT("1600 1200 70"),
	TEXT("1600 1200 75"),
	TEXT("1600 1200 85"),
	TEXT("1600 1200 90"),
	TEXT("1600 1200 100"),
	TEXT("1920 1440 60"),
	TEXT("1920 1440 75"),
	TEXT("1920 1440 85"),
	NULL
};

Display_LX::Display_LX()
{
}


Display_LX::~Display_LX()
{
}

BOOL Display_LX::IsSupported()
{

	BOOL rez = FALSE;
	HKEY hKey;

	if ( 0 == RegOpenKeyEx(HKEY_LOCAL_MACHINE, LX_IS_SUPPORTED,0,0, &hKey) )
	{
		rez = TRUE;
	}

	if ( hKey != NULL )
	{
		CloseRegistryKey(hKey);
	}

	return rez;
}

BOOL Display_LX::ModeIsSupported( DWORD width, 
			                       DWORD height,
						  		   DWORD colorDepth,
								   DWORD freq )
{
	TCHAR settings[100]={0};
	//if (colorDepth != 24 )
	//{
	//	return FALSE;
	//}

	if (freq > 80 )
	{
		return FALSE;
	}
	_stprintf(settings, TEXT("%d %d %d"),width, height, freq);
	
	for ( int i = 0; LXResolutions[i] != NULL; i++ )
	{
		if ( _tcsicmp(LXResolutions[i], settings) == 0 )
		{
			return TRUE;
		}
	}

	return FALSE;
}

BOOL Display_LX::TestModeIsSupported()
{
	return FALSE;
}

BOOL Display_LX::DisplayTest(DWORD width, 
			                       DWORD height,
							       DWORD colorDepth,
							       DWORD freq )
{
	return TRUE;    
}


void Display_LX::DisplayUpdate(DWORD width, 
								DWORD height,
							    DWORD colorDepth,
							    DWORD freq )
{
	TCHAR settings[100]={0};
	_stprintf(settings, TEXT("%d %d %d"),width, height, freq);

	for (int i = 0; LXResolutions[i] != NULL; i++ )
	{
		if ( _tcsicmp(LXResolutions[i], settings) == 0 )
		{
			HKEY hKey;

			if ( 0 == RegOpenKeyEx(HKEY_LOCAL_MACHINE, LX_DISPLAY_SETTINGS,0,0, &hKey) )
			{
				RegSetValueEx( hKey, LX_DISPLAY_RESOLUTION ,0, REG_SZ, (BYTE*)settings   , sizeof(TCHAR)*(_tcsclen(settings)+1));
			}

			if ( hKey != NULL )
			{
				CloseRegistryKey(hKey);
			}

			return;
		}
	}
}